package cc.io24.knewcafe.blog.service;


import cc.io24.knewcafe.blog.repository.BaseRepository;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

public class BaseService<T> {

    private BaseRepository dao;

    public Page<T> getList(T t, Pageable pageable){
        Example<T> example = Example.of(t);
        return dao.findAll(example,pageable);
    }

    public Page<T> getList(Pageable pageable){
        return dao.findAll(pageable);
    }

    public T getOne(String id){
        return (T)dao.findById(id).get();
    }

    public T insert(T t){
        return (T)dao.save(t);
    }

    public T update(T t){
        return (T)dao.save(t);
    }

    public void deleteById(String id){
        dao.deleteById(id);
    }

    public void setDao(BaseRepository dao) {
        this.dao = dao;
    }

    public BaseRepository getDao() {
        return dao;
    }
}
